﻿// Copyright © Microsoft Corporation.  All Rights Reserved.
// This code released under the terms of the 
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Browser;

namespace TheOliver.Controls
{
    public class HyperlinkAction : System.Windows.Interactivity.TargetedTriggerAction<FrameworkElement>
    {
        #region Properties to Expose
        [Category("Hyperlink Properties")]
        public string Url
        {
            get { return (string)GetValue(UrlProperty); }
            set { SetValue(UrlProperty, value); }
        }

        public static readonly DependencyProperty UrlProperty = DependencyProperty.Register("Hyperlink URL", typeof(string), typeof(HyperlinkAction), new PropertyMetadata("http://www.live.com"));

        [Category("Hyperlink Properties")]
        public string TargetURL
        {
            get { return (string)GetValue(TargetURLProperty); }
            set { SetValue(TargetURLProperty, value); }
        }

        public static readonly DependencyProperty TargetURLProperty = DependencyProperty.Register("TargetURL", typeof(string), typeof(HyperlinkAction), new PropertyMetadata("_self"));


        #endregion


        protected override void Invoke(object o)
        {
            if (Target != null)
            {
                HtmlPage.Window.Navigate(new Uri(Url), TargetURL);
            }
            else
            {
                HtmlPage.Window.Navigate(new Uri(Url), "_self");
            }
        }
    }
}
